package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {
    @Autowired
    private ApArticleService apArticleService;

    @PostMapping("/load/")
    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto) {
        // return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);

        return apArticleService.load2(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE,true);
    }
    @PostMapping("/loadmore/")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }
    @PostMapping("/loadnew/")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto) {
        return apArticleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }

//    @GetMapping("/newArticle")
//    public String newArticle() throws Exception {
//        apArticleService.newArticle();
//        return "ok";
//    }

    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {

        return apArticleService.saveArticle(dto);
    }
}
